package com.ufgov.smartclient.component.table;

import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;

/**
 * <p>Title: com.ufgov.smartclient.component</p>
 * <p>Description: 默认的合计行渲染器</p>
 * <p>Copyright: Copyright 2010 ufgov, Inc.</p>
 * <p>Company: ufgov</p>
 * <p>创建时间: 2010-3-29</p>
 * @author 刘永伟(manlge)
 * @version 1.0
 */
public class DefaultTableTotalLineCellRenderer extends JLabel implements
  TableTotalLineCellRenderer {
  private static final Border DEFAULT_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);

  private static final Border SAFE_NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);

  protected static Border noFocusBorder = DEFAULT_NO_FOCUS_BORDER;

  public DefaultTableTotalLineCellRenderer() {
    setOpaque(true);
    setPreferredSize(new Dimension(0, 18));
  }

  private Border getNoFocusBorder() {
    Border border = UIManager.getBorder("Table.cellNoFocusBorder");
    if (System.getSecurityManager() != null) {
      if (border != null)
        return border;
      return SAFE_NO_FOCUS_BORDER;
    } else if (border != null) {
      if (noFocusBorder == null || noFocusBorder == DEFAULT_NO_FOCUS_BORDER) {
        return border;
      }
    }
    return noFocusBorder;
  }

  @Override
  public Component getTableTotalLineCellRendererComponent(JGroupableTable table,
    Object value, int columIndex) {
    setText(String.valueOf(value));
    setBorder(getNoFocusBorder());
    return this;
  }
}
